package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级相关接口")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    // 分页查询所有护理等级
    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级")
    public ResponseResult<PageResponse> selectByPage(
            Integer pageNum,
            Integer pageSize,
            String name,
            Integer status// 状态：0：禁用，1：启用
    ) {
        return success(nursingLevelService.selectByPage(pageNum, pageSize, name, status));
    }

    // 新增护理等级
    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult create(@ApiParam(value = "护理等级数据传输对象", required = true)
                                 @RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.saveLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    // 根据id删除护理等级
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除护理等级")
    public int removeById(@PathVariable Long id) {
        return nursingLevelService.removeById(id);
    }

    // 根据id修改护理等级
    @PutMapping("/update")
    @ApiOperation(value = "根据id修改护理等级")
    public ResponseResult updateById(@RequestBody NursingLevelDto nursingLevelDto) {
        BeanUtil.copyProperties(nursingLevelDto, NursingLevel.class);
        nursingLevelService.updateById(nursingLevelDto);
        return ResponseResult.success();
    }

    // 根据id查询护理等级
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    // 启动或禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启动等级/禁用等级")
    public ResponseResult isEnable(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        nursingLevelService.isEnable(id, status);
        return success();
    }

    // 查询所有护理等级
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult selectAll() {
        List<NursingLevelVo> list = nursingLevelService.selectAll();
        return ResponseResult.success(list);
    }

    // 批量插入护理等级信息
    @PostMapping("/insertBatch")
    @ApiOperation(value = "批量插入护理等级信息")
    public ResponseResult insertBatch(
            @ApiParam(value = "护理等级数据列表", required = true)
            @RequestBody List<NursingLevelDto> nursingLevelDtos) {
        nursingLevelService.insertBatch(nursingLevelDtos);
        return ResponseResult.success();

    }
}
